package samfeng.erp.warehouse.dal.mysql;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;
import samfeng.erp.warehouse.controller.vo.WarehouseExportReqVO;
import samfeng.erp.warehouse.controller.vo.WarehousePageReqVO;
import samfeng.erp.warehouse.dal.dataobject.WarehouseDO;

/**
 * 仓库 Mapper
 *
 * @author samfeng
 */
@Mapper
public interface WarehouseMapper extends BaseMapperX<WarehouseDO> {

    default PageResult<WarehouseDO> selectPage(WarehousePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WarehouseDO>()
                .likeIfPresent(WarehouseDO::getName, reqVO.getName())
                .eqIfPresent(WarehouseDO::getDescription, reqVO.getDescription())
                .eqIfPresent(WarehouseDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(WarehouseDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(WarehouseDO::getCode, "".equals(reqVO.getCode())?null:reqVO.getCode())
                .eqIfPresent(WarehouseDO::getSequence, reqVO.getSequence())
                .orderByAsc(WarehouseDO::getSequence));
    }

    default List<WarehouseDO> selectList(WarehouseExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<WarehouseDO>()
                .likeIfPresent(WarehouseDO::getName, reqVO.getName())
                .eqIfPresent(WarehouseDO::getDescription, reqVO.getDescription())
                .eqIfPresent(WarehouseDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(WarehouseDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .eqIfPresent(WarehouseDO::getCode, reqVO.getCode())
                .eqIfPresent(WarehouseDO::getSequence, reqVO.getSequence())
                .orderByAsc(WarehouseDO::getSequence));
    }

}
